<?php

class Applicants_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function newApplicant() {
        $data = $_POST;
        unset($data['password2']);
        $data["last_modified"] = date("Y-m-d H:i:s");
        $this->db->insert('applicants', $data);
    }

    function updateApplicant($username) {
        $whr['username'] = $username;
        $data = $_POST;
        $data["last_modified"] = date("Y-m-d H:i:s");
        $this->db->update('applicants', $data, $whr);
    }

    function loggedApplicant($username) {

    }

    function validateLogin() {
        $data = $_POST;
        $this->db->where($data);
        $this->db->from('applicants');
        if ($this->db->count_all_results() > 0) {
            $whr['username'] = $username;
            $data["date_last_login"] = date("Y-m-d H:i:s");
            $this->db->update('applicants', $data, $whr);
            return TRUE;
        } else {
            return FALSE;
        }
    }

    function getProfile($username) {
        $data['username'] = $username;
        $this->db->where($data);
        $this->db->from('applicants');
        $query = $this->db->get();
        return $query->row();
    }

    function deleteApplicant($tid) {
        $data['tid'] = $tid;
        $this->db->where($data);
        $this->db->delete("applicants");
    }

}

/*
 *  //var_dump($data);
  $query="select * from applicants where username='" . $data['username'] . "' and password='" . $data['password'] . "'";
  echo $query;
  $query = $this->db->query($query);
  var_dump($query->num_rows());
  if ($query->num_rows() > 0) {
  return TRUE;
  } else {
  return FALSE;
  }
 */
?>
